<?php
namespace User\Model;

use Zend\InputFilter\InputFilterInterface;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
/**
 * 用户模型
 * @author Administrator
 *
 */
class Users
{
	public $id;
	public $username;
	public $password;
	public $realname;
	protected $inputFilter;
	
	public function exchangeArray($data)
	{
		$this->id = (isset($data['id'])) ? $data['id'] : NULL;
		$this->username = (isset($data['username'])) ? $data['username'] : NULL;
		$this->password = (isset($data['password'])) ? $data['password'] : NULL;
		$this->realname = (isset($data['realname'])) ? $data['realname'] : NULL;
	}
	
	/**
	 * @return $inputFilter
	 */
	public function getInputFilter()
	{
		if (!$this->inputFilter) {
			$inputFilter = new InputFilter();
			$factory = new InputFactory();
			
			$inputFilter->add($factory->createInput(array(
			    'name' => 'id',
			    'required' => true,
			    'filters' => array(
			        array('name' => 'Int'),
			    ),
			)));
			
			$inputFilter->add($factory->createInput(array(
			    'name' => 'username',
			    'required' => true,
			    'filters' => array(
			        array('name' => 'StripTags'),
			        array('name' => 'StringTrim'),
			    ),
			    'validators' => array(
			        array(
			            'name' => 'StringLength',
			            'options'  => array(
			                'min'      => 5,       // Minimum length
                            'max'      => 18,    // Maximum length, null if there is no length limitation
                            'encoding' => 'UTF-8',
			            ),
			        ),
			    ),
			)));
			
			$inputFilter->add($factory->createInput(array(
				'name' => 'password',
				'required' => true,
				'filters' => array(
						array('name' => 'StripTags'),
						array('name' => 'StringTrim'),
				),
				'validators' => array(
					array(
						'name' => 'StringLength',
						'options'  => array(
							'min'      => 6,       // Minimum length
							'max'      => 18,    // Maximum length, null if there is no length limitation
							'encoding' => 'UTF-8',
						),
					),
				),
			)));
			
			
			
			$inputFilter->add($factory->createInput(array(
				'name' => 'realname',
				'required' => true,
				'filters' => array(
					array('name' => 'StripTags'),
					array('name' => 'StringTrim'),
				),
				'validators' => array(
					array(
						'name' => 'StringLength',
						'options'  => array(
							'min'      => 2,       // Minimum length
							'max'      => 20,    // Maximum length, null if there is no length limitation
							'encoding' => 'UTF-8',
						),
					),
				),
			)));
			$this->inputFilter = $inputFilter;
		}
		return $this->inputFilter;
	}

	/**
	 * @param !CodeTemplates.settercomment.paramtagcontent!
	 */
	public function setInputFilter(InputFilterInterface $inputFilter)
	{
		throw new \Exception("Not use");
	}

	public function getArrayCopy()
	{
		return get_object_vars($this);
	}
}
?>